package com.freelancer.musicinstruction.services.impl.youtube;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;

import com.freelancer.musicinstruction.beans.interfaces.MusicInstruction;
import com.freelancer.musicinstruction.beans.youtube.YoutubeVideo;


public class YoutubeVideoContainer {
	
	public static final String TAG = YoutubeVideoContainer.class.getSimpleName();
	
	//private Long searchResultCount = 0L;
	
	//private Long searchStartIndex = 0L;
	
	private static final int LIST_LIMIT = 50;
	private static int attempts;
	
	private List<MusicInstruction> videos;
	
	private static YoutubeVideoContainer INSTANCE;
	
	private YoutubeVideoContainer() {
		Log.d(TAG, "constructor called");
		videos = new ArrayList<MusicInstruction>();
		attempts = 0;
	}
	
	public static YoutubeVideoContainer getInstance() {
		Log.d(TAG, "instance requested");
	     if( INSTANCE == null ){
	    	 INSTANCE = new YoutubeVideoContainer();
	     }
	     return INSTANCE;
	}
	
	public boolean addVideo ( YoutubeVideo video ){
		
		if( attempts > LIST_LIMIT ){
			return false;
		}
		
		attempts++;
		
		if ( video != null ){
			Log.d(TAG, "addVideo (videoTitle = "+video.getVideoTitle()+" )");
			videos.add( video );
			
			return true;
		}
		else{
			return false;
		}	
	}
	
	public boolean removeVideo ( int index ){
		if( index >= 0 && index < videos.size() ){
			videos.remove( index );
			return true;
		}
		else{
			return false;
		}
	}
	
	public void reset( ){
		//searchResultCount = 0L;
		INSTANCE = new YoutubeVideoContainer();
	}
	
	public void setSearchResultCount ( Long searchResultCount ){
		//this.searchResultCount = searchResultCount;
	}
	
	public void setSearchStartIndex ( Long searchStartIndex ){
		//this.searchStartIndex = searchStartIndex;
	}
	
	public List<MusicInstruction> getVideos(){
		return videos;
	}
}
